if(!jsx3.lang.Class.forName("tibco.admin.environments.keystore.Keystore")) {

    jsx3.lang.Class.defineClass("tibco.admin.environments.keystore.Keystore",
            jsx3.gui.Block,
            null,
            function (envKeystore) {
                envKeystore.prototype.mtxList = null;
                envKeystore.prototype.nodeName = null
                envKeystore.prototype.entityID = null;

                envKeystore.prototype.subscribeAll = function(strID) {
                    this.getDescendantOfName("btnEdit100").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                    this.mtxList = this.getDescendantOfName("mtxKeystoreList100");
                }

                envKeystore.prototype.loadDetails = function(strID, strNodeID, strNodeName) {
                    this.getDescendantOfName("btnEdit100").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                    this.mtxList = this.getDescendantOfName("mtxKeystoreList100");
                    this.entityID = strID;
                    this.nodeId = strNodeID;
                    this.nodeName = strNodeName;
                    this.callgetKeystoreEntriesAssociatedWithNode();
                }

                envKeystore.setToggle = function(jsxid, toggleMode) {
                    var document = tibco.admin.Main.getServer().getCache().getDocument("nodeKeystoreCache100");
                    var record = document.selectSingleNode("//record[@jsxid = '" + jsxid + "']");
                    if(record) {
                        record.setAttribute("associated", toggleMode);
                    }
                }

                envKeystore.prototype.callgetKeystoreEntriesAssociatedWithNode = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/environments/keystore/rules/getNodeMappingsForKeystoreRules.xml",
                            "getKeystoreEntriesAssociatedWithNode",
                            "Get keystore for nodes");
                    //subscribe and call
                    objService.entityID = this.entityID;
                    objService.nodeId = this.nodeId;
                    objService.nodeName = this.nodeName;
                    var me = this;
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.ongetKeystoreEntriesAssociatedWithNodeSuccess);
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getKeystoreEndpointURL());
                    objService.doCall();
                };

                envKeystore.prototype.ongetKeystoreEntriesAssociatedWithNodeSuccess = function(objEvent) {
                    if(!this.editDisabled && (this.mtxList.getXML().selectNodes("//record").getLength() > 0)) {
                        this.getDescendantOfName("btnEdit100").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                    }
                    this.mtxList.repaintData();
                    this.tempCacheDoc = this.mtxList.getXML().cloneDocument();
                    this.getDescendantOfName("selFilterEnable").setValue(tibco.admin.Main.getServer().getDynamicProperty("@@Filter Option All"));
                };

                envKeystore.prototype.callassociateKeystoreEntriesWithNode = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/environments/keystore/rules/editNodeMappingsForKeystoreRules.xml",
                            "associateKeystoreEntriesWithNode",
                            "associate keystores for nodes");
                    //subscribe and call
                    objService.entityID = this.entityID;
                    objService.nodeId = this.nodeId;
                    objService.nodeName = this.nodeName;
                    var me = this;
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.onassociateKeystoreEntriesWithNodeSuccess);
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getKeystoreEndpointURL())
                    objService.doCall();
                };

                envKeystore.prototype.onassociateKeystoreEntriesWithNodeSuccess = function(objEvent) {
                    this.callgetKeystoreEntriesAssociatedWithNode();
                    this.editSettings();
                };

                envKeystore.prototype.cancelEditSettings = function() {
                    this.editSettings();
                    this.callgetKeystoreEntriesAssociatedWithNode();
                }

                envKeystore.prototype.editSettings = function() {
                    var button = this.getDescendantOfName("btnEdit100");
                    if(!this.pluginObj.isInEditMode()) {
                        this.pluginObj.beginEditMode();
                        button.setDisplay(jsx3.gui.Block.DISPLAYNONE, true).
                                getParent().getChild("btnCancel100").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true).
                                getParent().getChild("btnAdd100").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                        this.getDescendantOfName("mcAssociated100").setValueTemplate(tibco.admin.Main.getServer().getDynamicProperty("@@Keystores Enabled Edit Mode Value Template100"));
                        this.getDescendantOfName("mcPassword100").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                        this.mtxList.repaint();
                    }
                    else {
                        this.pluginObj.endEditMode();
                        button.setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true).
                                getParent().getChild("btnCancel100").setDisplay(jsx3.gui.Block.DISPLAYNONE, true).
                                getParent().getChild("btnAdd100").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                        this.getDescendantOfName("mcAssociated100").setValueTemplate(tibco.admin.Main.getServer().getDynamicProperty("@@Keystores Enabled View Mode Value Template100"));
                        this.getDescendantOfName("mcPassword100").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                        this.mtxList.repaint();
                    }
                }

                envKeystore.prototype.onPropertyBeforeEdit = function(objGrid, objColumn, strRecordId) {
                    if(objColumn != objGrid.getChild("mcPassword100")) return false;
                    var objRecord = objGrid.getRecordNode(strRecordId);
                    var maskId = objRecord.getAttribute("associated");
                    return !(!maskId || maskId == "false");
                };

                envKeystore.prototype.filterResults = function() {
                    if(this.tempCacheDoc) {
                        var tempCacheDoc = this.tempCacheDoc;

                        var filterEnable = this.getDescendantOfName("selFilterEnable").getText();

                        if(filterEnable == tibco.admin.Main.getServer().getDynamicProperty("@@Filter Option All")) {
                            filterEnable = "All";
                        }
                        if(filterEnable == tibco.admin.Main.getServer().getDynamicProperty("@@Filter Option All Enabled")) {
                            filterEnable = "true";
                        }
                        if(filterEnable == tibco.admin.Main.getServer().getDynamicProperty("@@Filter Option All Not Enabled")) {
                            filterEnable = "false";
                        }

                        this.mtxList.setXMLTransformers(tibco.admin.Main.resolveURI("tibco.admin", "tibco/admin/environments/keystore/xsl/transform.xsl"));
                        this.mtxList.setXSLParam("enable", filterEnable);
                        this.mtxList.setSourceXML(tempCacheDoc);
                        this.mtxList.repaintData();
                    }
                };
            })
}